/**
 * <pre>
 * @(#)ScrollBarUIImpl.java 1.00 2009-10-29
 * 
 * Copyright (c) 1998, 2009 Regular Individual. All rights reserved.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *    http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * Contributor(s):
 *     Haixu Huang
 * </pre>
 **/
package cn.sh.huang.chart.ext.ui.plain;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.IOException;

import javax.imageio.ImageIO;

import cn.sh.huang.chart.ext.ui.ScrollBarUI;
import cn.sh.huang.chart.view.container.ScrollView;

/**
 * <pre>
 * ScrollBarUIImpl ...
 * 
 * @version 1.0
 * </pre>
 */
public class ScrollBarUIImpl extends ScrollBarUI
{
    private static final int unit = 14;
    private static final int[] idxz = { 0, 14, 21, 22, 29, 43, 47, 48, 56, 60 };
    /**
     * <code>
     * Texture for rendering scroll bar:
     * 
     *     left arrow 0, left side of slideway 1, extension of slideway 2, right side of slideway 3,
     *     right arrow 4, left side of slider 5, extension of slider 6, knot 7, right side of slider 8
     * 
     * |0|1| 2 |5|6|7|6|8| 2 |3|4|9
     * [<]{=====[   #   ]=====}[>]
     * </code>
     */

    private static final Image hbar, vbar;

    static {
        Image hbarImage = null, vbarImage = null;
        try {
            Class cls = ScrollBarUIImpl.class;
            hbarImage = ImageIO.read(cls.getResourceAsStream("scrollbar.png"));
            vbarImage =
                new BufferedImage(hbarImage.getHeight(null), hbarImage.getWidth(null), BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2d = (Graphics2D) vbarImage.getGraphics();
            g2d.rotate(-Math.PI / 2);
            g2d.scale(-1, 1);
            g2d.drawImage(hbarImage, 0, 0, null);

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            hbar = hbarImage;
            vbar = vbarImage;
        }
    }

    public ScrollBarUIImpl(ScrollView view)
    {
        super(view);
    }

    public int getBarUnit()
    {
        return unit;
    }

    /*
     * (non-Javadoc)
     * @see cn.sh.huang.chart.ext.ui.ScrollBarUI#getHbarTexture()
     */
    protected Image getHbarTexture()
    {
        return hbar;
    }

    /*
     * (non-Javadoc)
     * @see cn.sh.huang.chart.ext.ui.ScrollBarUI#getTextureIdxz()
     */
    protected int[] getTextureIdxz()
    {
        return idxz;
    }

    /*
     * (non-Javadoc)
     * @see cn.sh.huang.chart.ext.ui.ScrollBarUI#getVbarTexture()
     */
    protected Image getVbarTexture()
    {
        return vbar;
    }
}
